package com.ydj.framework.protocol;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ydj.framework.mysql.PageArgs;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.validation.constraints.Min;

/**
 * 请求页面参数
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class JsonPageRequest extends JsonBaseRequest {
    @ApiModelProperty(value = "当前页码", required = true, example = "1")
    protected Long page = 1L;

    /**
     * 页面大小
     */
    @ApiModelProperty(value = "页面数量", required = true, example = "20")
    protected Long pageSize = 20L;

    @JsonIgnore
    private PageArgs pageArgs = new PageArgs(page, pageSize);

    public PageArgs getPageArgs() {
        pageArgs.setPage(this.page)
                .setPageSize(this.pageSize);
        return pageArgs;
    }

    public JsonPageRequest setPageArgs(PageArgs pageArgs) {
        this.page = pageArgs.getPage();
        this.pageSize = pageArgs.getPageSize();
        this.pageArgs = pageArgs;
        return this;
    }
}